var appInstance = getApp(), dataApi = require("../../provider/dataApi.js");

require("../../provider/pipe.js");

Page({
    data: {
        statusBarHeight: "",
        titleBarHeight: "",
        userInfo: "",
        examInfo: {
            totalScore: 100,
            passScore: 60,
            paperTime: 90,
            highest: 0
        }
    },
    onLoad: function(options) {
        wx.getStorageSync("uid") ? (options = wx.getStorageSync("userinfo"), this.setData({
            statusBarHeight: appInstance.globalData.statusBarHeight,
            titleBarHeight: appInstance.globalData.titleBarHeight,
            userInfo: options
        }), this.fetchExamInfo()) : wx.navigateTo({
            url: "/pages/login/login"
        });
    },
    goBack: function() {
        wx.navigateBack({
            delta: 1
        });
    },
    goExam: function(event) {
        console.log(event), appInstance.globalData.selectedItem = event.currentTarget.dataset.item, wx.navigateTo({
            url: "../exam/exam?exam_type=" + event.currentTarget.id
        });
    },
    goSimulate: function(event) {
        appInstance.globalData.selectedItem = event.currentTarget.dataset.item, wx.navigateTo({
            url: "/pages/type-lx/type-lx?type=" + event.currentTarget.id
        });
    },
    onShow: function() {
        this.fetchExamInfo();
    },
    fetchExamInfo: function() {
        var that = this;
        dataApi.preExamInfo({
            uid: wx.getStorageSync("uid")
        }).then(function(response) {
            response.data.highest || (response.data.highest = 0), that.setData({
                examInfo: response.data
            });
        }).catch(function(error) {
            console.log(error);
        });
    },
    onShareAppMessage: function() {}
});